package com.qfedu.aunt.commons.config;

import com.baomidou.mybatisplus.core.injector.ISqlInjector;
import com.baomidou.mybatisplus.extension.injector.LogicSqlInjector;
import com.baomidou.mybatisplus.extension.plugins.OptimisticLockerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.baomidou.mybatisplus.extension.plugins.PerformanceInterceptor;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Profile;

/**
 * @author xiaobobo
 * @title: MyBatisPlusConfig
 * @projectName cd-2209-springboot-parent
 * @description: TODO
 * @date 2022/10/20  10:34
 */
@SpringBootConfiguration
public class MyBatisPlusConfig {


    /**
     * 配置的是离线乐观锁的插件
     * @return
     */
    @Bean
    public OptimisticLockerInterceptor optimisticLockerInterceptor(){
        return new OptimisticLockerInterceptor();
    }

    //下面需要配置的是逻辑删除的插件
    /**
     * 逻辑删除的插件
     * @return
     */
    @Bean
    public ISqlInjector iSqlInjector(){
        return new LogicSqlInjector();
    }

    /**
     * 添加分页插件
     * @return
     */
    @Bean
    public PaginationInterceptor paginationInterceptor(){
        return new PaginationInterceptor();
    }


    @Bean
    @Profile({"dev","test"})   //下面这个插件在哪些环境生效
    public PerformanceInterceptor performanceInterceptor(){
        PerformanceInterceptor performanceInterceptor = new PerformanceInterceptor();
        //单位是毫秒 只要运行时间大于5毫秒 那么就报错不执行了
        performanceInterceptor.setMaxTime(100000);
        performanceInterceptor.setFormat(true);
        return performanceInterceptor;
    }

}
